home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / 2d / disc.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  4KB  |  179 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/2d/disc.c,v $
  15.  * $Revision: 1.3 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/11/09 22:20:07 $
  18.  *
  19.  * Graphical routines for drawing a disk.
  20.  *
  21.  * $Log: disc.c,v $
  22.  * Revision 1.3  1998/11/09 22:20:07  nobody
  23.  * *** empty log message ***
  24.  *
  25.  * Revision 1.2  1998/03/31 17:03:00  hfrieden
  26.  * Added ViRGE direct rendering stuff
  27.  *
  28.  * Revision 1.1.1.1  1998/03/03 15:11:45  nobody
  29.  * reimport after crash from backup
  30.  *
  31.  * Revision 1.1.1.1  1998/02/13  20:21:20  hfrieden
  32.  * Initial Import
  33.  *
  34.  * Revision 1.1  1995/03/09  08:52:14  allender
  35.  * Initial revision
  36.  *
  37.  *
  38.  * --- PC RCS information ---
  39.  * Revision 1.5  1994/11/18  22:50:16  john
  40.  * Changed shorts to ints in parameters.
  41.  * 
  42.  * Revision 1.4  1994/05/06  12:50:12  john
  43.  * Added supertransparency; neatend things up; took out warnings.
  44.  * 
  45.  * Revision 1.3  1994/04/22  11:16:04  john
  46.  * *** empty log message ***
  47.  * 
  48.  * Revision 1.2  1993/10/15  16:22:24  john
  49.  * *** empty log message ***
  50.  * 
  51.  * Revision 1.1  1993/09/08  11:43:24  john
  52.  * Initial revision
  53.  * 
  54.  *
  55.  */
  56.  
  57. #include "mem.h"
  58. #include "gr.h"
  59. #include "grdef.h"
  60.  
  61. int gr_disk(fix xc1,fix yc1,fix r1)
  62. {
  63.     int p,x, y, xc, yc, r;
  64.  
  65.     r = f2i(r1);
  66.     xc = f2i(xc1);
  67.     yc = f2i(yc1);
  68.     p=3-(r*2);
  69.     x=0;
  70.     y=r;
  71.  
  72.     // Big clip
  73.     if ( (xc+r) < 0 ) return 1;
  74.     if ( (xc-r) > GWIDTH ) return 1;
  75.     if ( (yc+r) < 0 ) return 1;
  76.     if ( (yc-r) > GHEIGHT ) return 1;
  77.  
  78.     while(x<y)
  79.     {
  80.         // Draw the first octant
  81.         gr_scanline( xc-y, xc+y, yc-x );
  82.         gr_scanline( xc-y, xc+y, yc+x );
  83.  
  84.         if (p<0) 
  85.             p=p+(x<<2)+6;
  86.         else    {
  87.             // Draw the second octant
  88.             gr_scanline( xc-x, xc+x, yc-y );
  89.             gr_scanline( xc-x, xc+x, yc+y );
  90.             p=p+((x-y)<<2)+10;
  91.             y--;
  92.         }
  93.         x++;
  94.     }
  95.     if(x==y)    {
  96.         gr_scanline( xc-x, xc+x, yc-y );
  97.         gr_scanline( xc-x, xc+x, yc+y );
  98.     }
  99.     return 0;
  100. }
  101.  
  102. #if defined(VIRGIN) || defined(WARP3D)
  103. int gr_direct_disk(fix xc1,fix yc1,fix r1)
  104. {
  105.     int p,x, y, xc, yc, r;
  106.  
  107.     r = f2i(r1);
  108.     xc = f2i(xc1);
  109.     yc = f2i(yc1);
  110.     p=3-(r*2);
  111.     x=0;
  112.     y=r;
  113.  
  114.     // Big clip
  115.     if ( (xc+r) < 0 ) return 1;
  116.     if ( (xc-r) > GWIDTH ) return 1;
  117.     if ( (yc+r) < 0 ) return 1;
  118.     if ( (yc-r) > GHEIGHT ) return 1;
  119.  
  120.     while(x<y)
  121.     {
  122.         // Draw the first octant
  123.         gr_direct_scanline( xc-y, xc+y, yc-x );
  124.         gr_direct_scanline( xc-y, xc+y, yc+x );
  125.  
  126.         if (p<0)
  127.             p=p+(x<<2)+6;
  128.         else    {
  129.             // Draw the second octant
  130.             gr_direct_scanline( xc-x, xc+x, yc-y );
  131.             gr_direct_scanline( xc-x, xc+x, yc+y );
  132.             p=p+((x-y)<<2)+10;
  133.             y--;
  134.         }
  135.         x++;
  136.     }
  137.     if(x==y)    {
  138.         gr_direct_scanline( xc-x, xc+x, yc-y );
  139.         gr_direct_scanline( xc-x, xc+x, yc+y );
  140.     }
  141.     return 0;
  142. }
  143. #endif
  144.  
  145. int gr_udisk(fix xc1,fix yc1,fix r1)
  146. {
  147.     int p,x, y, xc, yc, r;
  148.  
  149.     r = f2i(r1);
  150.     xc = f2i(xc1);
  151.     yc = f2i(yc1);
  152.     p=3-(r*2);
  153.     x=0;
  154.     y=r;
  155.  
  156.     while(x<y)
  157.     {
  158.         // Draw the first octant
  159.         gr_uscanline( xc-y, xc+y, yc-x );
  160.         gr_uscanline( xc-y, xc+y, yc+x );
  161.  
  162.         if (p<0) 
  163.             p=p+(x<<2)+6;
  164.         else    {
  165.             // Draw the second octant
  166.             gr_uscanline( xc-x, xc+x, yc-y );
  167.             gr_uscanline( xc-x, xc+x, yc+y );
  168.             p=p+((x-y)<<2)+10;
  169.             y--;
  170.         }
  171.         x++;
  172.     }
  173.     if(x==y)    {
  174.         gr_uscanline( xc-x, xc+x, yc-y );
  175.         gr_uscanline( xc-x, xc+x, yc+y );
  176.     }
  177.     return 0;
  178. }
  179.